<!--
 * @Description: 
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-04-28 11:30:41
 * @LastEditors: Yuanjy
 * @LastEditTime: 2020-05-07 18:11:20
 -->
<template>
  <div class="app-container">
    <eHeader :roles="roles" :query="query" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" border style="width: 100%;">
      <el-table-column prop="name" label="tab名称" />
      <el-table-column prop="short" label="缩写" />
      <el-table-column label="背景图">
        <template slot-scope="scope">
          <img :src="scope.row.bg_img" class="el-avatar">
        </template>
      </el-table-column>
      <el-table-column prop="font_size" label="字号" />
      <el-table-column label="字体颜色">
        <template slot-scope="scope">
          <el-tag :color=scope.row.font_color></el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否加粗">
        <template slot-scope="scope">
          <span>{{ scope.row.is_font_weight ? '是':'否' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="add_at" label="添加日期" />
      <el-table-column label="操作" align="center" width="180px">
        <template slot-scope="scope">
          <edit
            v-if="checkPermission(['ADMIN','USER_ALL','USER_EDIT'])"
            :data="scope.row"
            :roles="roles"
            :sup_this="sup_this"
          />
          <el-popover
            v-if="checkPermission(['ADMIN','USER_ALL','USER_DELETE'])"
            :ref="scope.row.id"
            placement="top"
            width="180"
          >
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button
                :loading="delLoading"
                type="primary"
                size="mini"
                @click="subDelete(scope.row.id)"
              >确定</el-button>
            </div>
            <!-- <el-tooltip slot="reference" content="删除用户" placement="top">
              <svg-icon :disabled="scope.row.id === 1" icon-class="delete" class-name="edit-icon" />
            </el-tooltip> -->
            <el-button slot="reference" :disabled="scope.row.id === 1" type="danger" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'

export default {
  components: { eHeader, edit },
  mixins: [initData],
  data() {
    return {
      roles: [],
      delLoading: false,
      sup_this: this,
      dialogVisible: false,
      dialogVisible2: false,
      userName: 'admin',
      total2: 0,
      sizes2: 10,
      page2: 0,
      user_name: '',
      userSearchName: '',
      page_size: 10,
      updateId: null
    }
  },
  created() {
    this.getRoles()
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    checkPermission,
    beforeInit() {
      this.url = '/admin/v1/config-tab'
      const query = this.query
      const value = query.value
      this.params = { page: this.page, limit: this.limit }
      if (value) {
        this.params['name'] = value
      }
      return true
    },
    getRoles() {
      this.$api.permission.role
        .getRoleTree({})
        .then(res => {
          this.roles = res.data
        })
    },
    subDelete(id) {
      this.delLoading = true
      this.$api.permission.tabConfig
        .del(id)
        .then(res => {
          this.delLoading = false
          this.$refs[id].doClose()
          this.init()
          this.$notify({ title: '删除成功', type: 'success', duration: 2500 })
        })
        .catch(err => {
          this.delLoading = false
          this.$refs[id].doClose()
          console.log(err.response.data.message)
        })
    },
    trim(str) {
      if (str) {
        return str.replace(/(^\s*)|(\s*$)/g, '')
      } else {
        return str
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  height: 36px;
  line-height: 36px;
}
.edit-icon {
  width: 1.5em;
  height: 1.5em;
}
</style>

